<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p><input type="text" value="1,2,3,4,5"><span>输入数字求和</span></p>
    <p>求和</p>
    <!-- <button>求和</button> -->
</body>
<script>
    var inp=document.querySelector('input')
    var p=document.querySelector('p')
    p.onclick=function(){
        var sum=0
        var inpvalue=inp.value.split(',')
        console.log(inpvalue);
        for(let i=0;i<inpvalue.length;i++){
            sum+=parseInt(inpvalue[i])
        }
        alert(sum)
    }
</script>
</html>